<?php

namespace App\Http\Controllers;

use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Db;

class Controller extends BaseController
{

    /**
     *
     * @OA\Info(
     *     version="1.0.0",
     *     title="指兴云链商城",
     *     description="finger",
     *     @OA\Contact(
     *         email="18301922335",
     *         name="weilisi"
     *     )
     * )
     * @OA\Server(
     *     url="http://fingerapi.test.dianduidian.tech",
     *     description="用户 管理，矿机 收益",
     * )
     */
    protected $user;
    protected $admin;
    public function __construct(){
        $this->user = Auth::user();
        $this->admin = Auth::guard('admin')->user();
        if(!Cache::get('config_level')){
            $config_level = Db::table('config_level')->get();
            $config_level_arr = [];
            foreach($config_level as $val){
                $config_level_arr[$val->level] = $val;
            }
            Cache::set('config_level',$config_level);
            unset($config_level_arr);
        }

        if(!Cache::get('config_products')){
            $config_products = Db::table('config_products')->get()->toArray();
            Cache::set('config_products',$config_products);
        }

        if(!Cache::get('config_sys')){
            $config_sys = Db::table('config_sys')->where('state','normal')->get()->toArray();
            Cache::set('config_sys',$config_sys);
        }
        if(!Cache::get('configs')){
            $config_sys = Db::table('config_sys')->where('state','normal')->get()->toArray();;
            $config_arr = [];
            foreach($config_sys as $v){
                $config_arr[$v->type][$v->key] = $v;
            }
            Cache::set('configs',$config_arr);
        }

    }
}
